home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / CPP100.ZIP / CPPLMEN1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  12.4 KB  |  398 lines

  1. /*****************************************************************************/
  2. /*       (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved         */
  3. /*****************************************************************************/
  4. /*    This source-code is NOT public domain nor Freeware, this is part of    */
  5. /*              'The C Programming Package' which is Shareware.              */
  6. /*   If you use this code, please register and get a free Full-VGA version   */
  7. /*****************************************************************************/
  8.                                /*----------------*
  9.                                 *   CPPLMEN1.C   *
  10.                                 * Menu manager1  *
  11.                                 *     Files      *
  12.                                 *----------------*/
  13.  
  14.  /* Included Files */
  15.  # include <stdio.h>
  16.  # include <io.h>
  17.  # include <dos.h>
  18.  # include <fcntl.h>
  19.  # include <bios.h>
  20.  # include <stdlib.h>
  21.  # include <conio.h>
  22.  
  23.  /* Global Variables */
  24.  extern int bm,i,j,k,l,m,n,t,x,x1,x2,xm,y,y1,y2,ym,z,menu0,menu1,return1;
  25.  extern int colour1,colour2,colour3,colour4,colour5,return2;
  26.  extern unsigned char c0,c1,trashcan[];
  27.  
  28.  /*----------------------*
  29.   * CHOICE DISPLAY HELP1 *
  30.   *----------------------*/
  31.   void choice_display_help1()
  32.     {
  33.       /* We display the help that concerns the line on */
  34.       /* which is the menu cursor (in red).            */
  35.       if(menu1==1){
  36.         /* Open a file */
  37.         display_help("FILES   ",5,2,1);     restore_help_screen();
  38.       }
  39.       if(menu1==2){
  40.         /* Create a new file */
  41.         display_help("FILES   ",6,3,1);     restore_help_screen();
  42.       }
  43.       if(menu1==3){
  44.         /* Save the info. in the current file */
  45.         display_help("FILES   ",7,4,1);     restore_help_screen();
  46.       }
  47.       if(menu1==4){
  48.         /* available */
  49.         display_help("FILES   ",8,5,1);     restore_help_screen();
  50.       }
  51.       if(menu1==5){
  52.         /* Directory manager */
  53.         display_help("FILES   ",9,6,1);     restore_help_screen();
  54.       }
  55.       if(menu1==6){
  56.         /* Directory change */
  57.         display_help("FILES   ",10,7,1);     restore_help_screen();
  58.       }
  59.       if(menu1==7){
  60.         /* available */
  61.         display_help("FILES   ",11,8,1);     restore_help_screen();
  62.       }
  63.       if(menu1==8){
  64.         /* Print */
  65.         display_help("FILES   ",12,9,1);     restore_help_screen();
  66.       }
  67.       if(menu1==9){
  68.         /* Copy to file */
  69.         display_help("FILES   ",13,10,1);     restore_help_screen();
  70.       }
  71.       if(menu1==10){
  72.         /* Quit to DOS */
  73.         display_help("FILES   ",14,11,1);    restore_help_screen();
  74.       }
  75.     }
  76.  /*----------------*
  77.   * GET THE MOUSE1 *
  78.   *----------------*/
  79.   int get_the_mouse1()
  80.     {
  81.       /* If we choose with the mouse */
  82.       /* Only available for menu 1   */
  83.       if(ym==1){
  84.         /* We clicked on the first line, certainly */
  85.         /* To change of menu.                      */
  86.         x=get_the_mouse0();
  87.     menu0=x;                       return(-2);
  88.       }
  89.       if((xm>1)&&(xm<19)){
  90.     if(ym==3){
  91.        /* Open a file */
  92.       menu1=1;                   return(1);
  93.     }
  94.     if(ym==4){
  95.           /* Create a new file */
  96.       menu1=2;                     return(1);
  97.     }
  98.     if(ym==5){
  99.           /* Save the info. in a file */
  100.       menu1=3;                     return(1);
  101.     }
  102.     if(ym==6){
  103.           /* Choix (available) */
  104.       menu1=4;                     return(1);
  105.     }
  106.     if(ym==8){
  107.           /* Directory manager */
  108.       menu1=5;                     return(1);
  109.     }
  110.     if(ym==9){
  111.           /* Directory change */
  112.       menu1=6;                     return(1);
  113.     }
  114.     if(ym==10){
  115.           /*  (available) */
  116.       menu1=7;                     return(1);
  117.     }
  118.     if(ym==12){
  119.           /*  print */
  120.       menu1=8;                     return(1);
  121.     }
  122.     if(ym==13){
  123.           /* copy to file */
  124.       menu1=9;                     return(1);
  125.     }
  126.     if(ym==15){
  127.           /* Quit */
  128.       menu1=10;                    return(-1);
  129.     }
  130.       }
  131.       /* If we clicked outside the menu zone            */
  132.       /* we want to erase the menu and return to menu 0 */
  133.  
  134.       menu0=0;                         return(-2);
  135.     }
  136.  /*---------------------*
  137.   * GET KEYBOARD INPUT1 *
  138.   *---------------------*/
  139.   int get_keyboard_input1()
  140.     {
  141.       /* Standard keyboard keys */
  142.       if(c1==27){
  143.         /* <Esc> we want to go back to menu0 */
  144.     menu0=0;                       return(-2);
  145.       }
  146.       if((c1==81)||(c1==113)){
  147.         /* <Q> <q> quit */
  148.     menu1=10;                   return(-1);
  149.       }
  150.       if(c1==13){
  151.         /* <Enter> execute the command */
  152.     return(1);
  153.       }
  154.       if((c1==79)||(c1==111)){
  155.         /* <O> <o> Open file */
  156.     menu1=1;                       return(1);
  157.       }
  158.       if((c1==78)||(c1==110)){
  159.         /* <N> <n> Create new file */
  160.     menu1=2;                       return(1);
  161.       }
  162.       if((c1==83)||(c1==115)){
  163.         /* <S> <s> Save info. in current file */
  164.     menu1=3;                       return(1);
  165.       }
  166.       if((c1==65)||(c1==97)){
  167.         /* <A> <a> Save as... */
  168.     menu1=4;                       return(1);
  169.       }
  170.       if((c1==68)||(c1==100)){
  171.         /* <D> <d> Directory manager */
  172.     menu1=5;                       return(1);
  173.       }
  174.       if((c1==66)||(c1==98)){
  175.         /* <B> <b> Back to the default directory */
  176.     menu1=6;                       return(1);
  177.       }
  178.       if((c1==82)||(c1==114)){
  179.         /* <R> <r> Recording the file */
  180.     menu1=7;                       return(1);
  181.       }
  182.       if((c1==80)||(c1==112)){
  183.         /* <P> <p> Print */
  184.     menu1=8;                       return(1);
  185.       }
  186.       if((c1==84)||(c1==116)){
  187.         /* <T> <t> copy to a file */
  188.     menu1=9;                       return(1);
  189.       }
  190.       return(0);
  191.     }
  192.  /*-----------------*
  193.   * SPECIAL DECODE1 *
  194.   *-----------------*/
  195.   int special_decode1()
  196.     {
  197.       /* For the 2-bytes coded keys, this is the second byte */
  198.       if(c1==59){
  199.          /* Function key <F1> = help */
  200.      return(22);
  201.       }
  202.       k=get_special_menu00();
  203.       if(k>0)                          return(-2);
  204.       if(c1==72){
  205.         /* Up arrow */
  206.     if(menu1>1)                    menu1--;
  207.     else                           menu1=10;
  208.     return(0);
  209.       }
  210.       if(c1==80){
  211.         /* Down arrow */
  212.     if(menu1<10)                   menu1++;
  213.     else                           menu1=1;
  214.     return(0);
  215.       }
  216.       return(0);
  217.     }
  218.  /*--------------*
  219.   * MENU CHOICE1 *
  220.   *--------------*/
  221.   int menu_choice1()
  222.     {
  223.       /* We do nothing until a key is pressed                */
  224.       /* or we pressed a mouse button.                       */
  225.       /* We use the 'l' return to test if the key pressed    */
  226.       /* or the mouse choice is one we are waiting for       */
  227.       /* else we wait a valid key                            */
  228.       /* Notice that Up and Down arrows only move the cursor */
  229.       /* and we need to confirm it with <Enter>              */
  230.       while(1){
  231.     if(kbhit()){
  232.           /* If we pressed a key */
  233.       c1=getch();
  234.       if(c1>0){
  235.             t=get_keyboard_input1();  break;
  236.       }
  237.       else{
  238.             /* Key coded on 2 bytes */
  239.         c1=getch();
  240.             t=special_decode1();     break;
  241.       }
  242.     }
  243.         /* Else we test the mouse */
  244.         get_mouse_state();
  245.     if(bm==1){
  246.           /* We pressed a mouse button */
  247.           t=get_the_mouse1();  break;
  248.     }
  249.       }
  250.       /* We translate the result and send it back */
  251.       return(t);
  252.     }
  253.  /*--------------------*
  254.   * DISPLAY MENU LINE1 *
  255.   *--------------------*/
  256.   void display_menu_line1()
  257.     {
  258.       /* First we display the chosen menu0 */
  259.       textattr(colour5);
  260.       gotoxy(1,1);                     cputs(" Files  ");
  261.       /* Same thing for the selected line */
  262.       if(menu1==1){
  263.         gotoxy(3,3);                   cputs(" Open           ");
  264.       }
  265.       if(menu1==2){
  266.         gotoxy(3,4);                   cputs(" New            ");
  267.       }
  268.       if(menu1==3){
  269.         gotoxy(3,5);                   cputs(" Save           ");
  270.       }
  271.       if(menu1==4){
  272.         gotoxy(3,6);                   cputs(" save As...     ");
  273.       }
  274.       if(menu1==5){
  275.         gotoxy(3,8);                   cputs(" Directory mgr  ");
  276.       }
  277.       if(menu1==6){
  278.         gotoxy(3,9);                   cputs(" Back deflt dir ");
  279.       }
  280.       if(menu1==7){
  281.         gotoxy(3,10);                  cputs(" Record file    ");
  282.       }
  283.       if(menu1==8){
  284.         gotoxy(3,12);                  cputs(" Print          ");
  285.       }
  286.       if(menu1==9){
  287.         gotoxy(3,13);                  cputs(" To a file      ");
  288.       }
  289.       if(menu1==10){
  290.         gotoxy(3,15);                  cputs(" Quit to DOS    ");
  291.       }
  292.     }
  293.  /*----------------------*
  294.   * DISPLAY KEY LETTER 1 *
  295.   *----------------------*/
  296.   void display_key_letter1()
  297.     {
  298.       textattr(116);
  299.       gotoxy(4,3);                     cputs("O");
  300.       gotoxy(4,4);                     cputs("N");
  301.       gotoxy(4,5);                     cputs("S");
  302.       gotoxy(9,6);                     cputs("A");
  303.       gotoxy(4,8);                     cputs("D");
  304.       gotoxy(4,9);                     cputs("B");
  305.       gotoxy(4,10);                    cputs("R");
  306.       gotoxy(4,12);                    cputs("P");
  307.       gotoxy(4,13);                    cputs("T");
  308.       gotoxy(4,15);                    cputs("Q");
  309.     }
  310.  /*---------------*
  311.   * DISPLAY MENU1 *
  312.   *---------------*/
  313.   void display_menu1()
  314.     {
  315.       /* To avoid the trace of the previous mouse position */
  316.       /* we hide it during the display,                    */
  317.       /* and show it when the line has been displayed.     */
  318.       hide_the_mouse();               textattr(colour2);
  319.       gotoxy(1,2);                     cputs(" ┌────────────────┐ ");
  320.       gotoxy(1,3);                     cputs(" │ Open           │ ");
  321.       gotoxy(1,4);                     cputs(" │ New            │ ");
  322.       gotoxy(1,5);                     cputs(" │ Save           │ ");
  323.       gotoxy(1,6);                     cputs(" │ save As        │ ");
  324.       gotoxy(1,7);                     cputs(" ├────────────────┤ ");
  325.       gotoxy(1,8);                     cputs(" │ Directory mgr  │ ");
  326.       gotoxy(1,9);                     cputs(" │ Back Deflt Dir │ ");
  327.       gotoxy(1,10);                    cputs(" │ Record File    │ ");
  328.       gotoxy(1,11);                    cputs(" ├────────────────┤ ");
  329.       gotoxy(1,12);                    cputs(" │ Print          │ ");
  330.       gotoxy(1,13);                    cputs(" │ To a file      │ ");
  331.       gotoxy(1,14);                    cputs(" ├────────────────┤ ");
  332.       gotoxy(1,15);                    cputs(" │ Quit to DOS    │ ");
  333.       gotoxy(1,16);                    cputs(" └────────────────┘ ");
  334.       display_key_letter1();           display_menu_line1();
  335.       show_the_mouse();
  336.     }
  337.  /*----------------*
  338.   * MENU MANAGER 1 *
  339.   *----------------*/
  340.   int menu_manager1()
  341.     {
  342.       restore_screen();                return1=0;
  343.       while(1){
  344.         display_menu1();               return1=menu_choice1();
  345.         if(return1==-2)                return(-2);
  346.         if(return1==-1)                return(-1);
  347.         if(return1==22)                choice_display_help1();
  348.         display_menu1();
  349.         if(return1==1){
  350.           /* We execute the selected function */
  351.       if(menu1==10){
  352.             /* we want to quit to DOS */
  353.         return(-1);
  354.       }
  355.       if(menu1==1){
  356.             /* Open a file */
  357.             gotoxy(1,25); printf(" Open a file. Press <SPACE> please.");
  358.             getch();      /* We erase the line */
  359.         gotoxy(1,25); printf("                                        ");
  360.       }
  361.       if(menu1==2){
  362.             /* create a new file */
  363.  
  364.       }
  365.       if(menu1==3){
  366.             /* Save info. in the current file */
  367.  
  368.       }
  369.       if(menu1==4){
  370.             /* Save as */
  371.  
  372.       }
  373.       if(menu1==5){
  374.             /* Directory/drives manager */
  375.             directory_change();
  376.       }
  377.       if(menu1==6){
  378.           /* Back to the default directory stored in the */
  379.           /* service file in "path" */
  380.             back_to_default_directory();
  381.       }
  382.       if(menu1==7){
  383.             /* Recording of the files Cf MODFIC3.C */
  384.             file_recording();
  385.       }
  386.       if(menu1==8){
  387.             /* Print */
  388.  
  389.       }
  390.       if(menu1==9){
  391.             /* Copy to a file */
  392.  
  393.       }
  394.     }
  395.       }
  396.     }
  397. /* End of the Module *//*----------------*/
  398.